﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.ComponentModel;
using DoAnWeb.DTO;

namespace DoAnWeb.DAO
{
    public class LoaiTaiKhoanDAO
    {
        DataProvider dp = new DataProvider();

        public BindingList<LoaiTaiKhoanDTO> GetList()
        {
            if (dp.OpenConnect())
            {
                DataTable dt = dp.SqlExcuteQuery("uproc_GetList_LoaiTaiKhoan", null);
                dp.CloseConnect();
                BindingList<LoaiTaiKhoanDTO> List = new BindingList<LoaiTaiKhoanDTO>();
                foreach (DataRow row in dt.Rows)
                {
                    LoaiTaiKhoanDTO DTO = new LoaiTaiKhoanDTO();
                    DTO.MaLoaiTaiKhoan = int.Parse(row["MaLoaiTaiKhoan"].ToString());
                    DTO.TenLoaiTaiKhoan = row["TenLoaiTaiKhoan"].ToString();
                    List.Add(DTO);
                }
                return List;
            }
            return null;
        }

        public BindingList<LoaiTaiKhoanDTO> GetFromID(int _Ma)
        {
            if (dp.OpenConnect())
            {
                SqlParameter[] sqlParameter = 
                { 
                    new SqlParameter("@MaLoaiTaiKhoan", _Ma) 
                };
                DataTable dt = dp.SqlExcuteQuery("uproc_GetFromID_LoaiTaiKhoan", sqlParameter);
                dp.CloseConnect();
                BindingList<LoaiTaiKhoanDTO> List = new BindingList<LoaiTaiKhoanDTO>();
                foreach (DataRow row in dt.Rows)
                {
                    LoaiTaiKhoanDTO DTO = new LoaiTaiKhoanDTO();
                    DTO.MaLoaiTaiKhoan = int.Parse(row["MaLoaiTaiKhoan"].ToString());
                    DTO.TenLoaiTaiKhoan = row["TenLoaiTaiKhoan"].ToString();
                    List.Add(DTO);
                }
                return List;
            }
            return null;
        }

    }
}